package com.zzyl.nursing.controller.member;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.domain.vo.PageResultVO;
import com.zzyl.nursing.service.IFamilyOrdersProjectService;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Acer
 */
@RequestMapping("/member/orders/project")
@RestController
public class FamilyOrdersProjectController {

    @Autowired
    private IFamilyOrdersProjectService familyOrdersProjectService;

    /***
     * 1.1 分页查询护理项目列表*/
    @GetMapping("/page")
    public PageResultVO<NursingProject> list(
            @Parameter String name,
            @Parameter Integer pageNum,
            @Parameter Integer pageSize,
            @Parameter Integer status
    ){
        LambdaQueryWrapper<NursingProject> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(name != null, NursingProject::getName, name)
                .eq(status != null, NursingProject::getStatus, status);
        Page<NursingProject> page = PageHelper.startPage(pageNum,pageSize)
                .doSelectPage(()-> familyOrdersProjectService.list(wrapper));

        return PageResultVO.<NursingProject>builder()
                .total((int)page.getTotal())
                .rows(page.getResult())
                .msg("查询成功")
                .code("200")
                .build();
    }

    /***
     * 1.2 根据编号查询护理项目信息*/
    @GetMapping("/{id}")
    public R<NursingProject> findNursingProjectById(@PathVariable Integer id){
        return R.ok(familyOrdersProjectService.getById(id));
    }
}
